package com.enjoy.ui;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.enjoy.R;
import com.enjoy.commons.Commons;
import com.enjoy.utils.HttpPostHandle;

import android.os.Bundle;
import android.os.StrictMode;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
	Button a;
	Button b;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState); ;;
		setContentView(R.layout.activity_main);
		
		StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
				.detectDiskReads().detectDiskWrites().detectNetwork()
				.penaltyLog().build());
		StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
				.detectLeakedSqlLiteObjects() 
				.penaltyLog().penaltyDeath().build());

		a = (Button) findViewById(R.id.button_test);
		b = (Button) findViewById(R.id.button_2222);

		a.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {

				HttpPostHandle handle = new HttpPostHandle(Commons.URL
						+ "serviceName=UserService&operation=insert");
				handle.add("longitude", 122.23434 + "");
				handle.add("latitude", -37.123 + "");
				handle.add("username", "testhaha");
				handle.add("sex", "female");
				handle.add("mobile", "15000692117");
				handle.add("password", "12341234");
				JSONObject JSON;
				JSON = handle.getResponse();
				a.setText(JSON.toString());
			}
		});
		
		b.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {

				HttpPostHandle httphandle = new HttpPostHandle(Commons.URL
						+ "serviceName=UserService&operation=identification");
				
				httphandle.add("username", "test23142134");
				httphandle.add("password", "12341234");
				JSONObject JSON;
				JSON = httphandle.getResponse();
				b.setText(JSON.toString());
			}
		});

	}
}
